package c3g;

import java.io.*;
import java.util.ArrayList;
import java.util.Properties;

public class Config {
    private String input;
    private String CMD;
    private String set_out;
    private String javavm;
    private String csvm;
    private String jsonvm;
    private ArrayList arrayList =new ArrayList();
    private String output;
    private String enumvm;
    private String protovm;
    private String readenum;
    private String readjava;
    private String input_back;
    private String out;
    private String sqlvm;
    private String input_sql;
    private String output_sql;



    //读取配置文件
    public void readconfig(Properties props,String filepro) throws IOException {

        InputStream inputStream = new FileInputStream(filepro);     //读取配置文件
        props.load(inputStream);
        input=(String) props.get("input");             //读取配置文件中读转化成make文件的文件路径
        CMD =(String)props.get("protocCMD");           //读取配置文件中protoc.exe的路径
        set_out =(String)props.get("set_out");         //读取配置文件中的des文件的生成路径
        javavm =(String) props.get("javavm");                  //读取配置文件中的javavm
        csvm =(String) props.get("csvm");                      //读取配置中的csvm
        jsonvm =(String) props.get("jsonvm");                  //读取配置中的jsonvm
        enumvm =(String) props.get("enumvm");                  //读取配置中的enumvm
        protovm =(String) props.get("protovm");                //读取配置中的protovm
        sqlvm =(String) props.get("sqlvm");                    //读取配置中的sqlvm
        output =(String) props.get("output");           //读取配置中make文件的生成路径
        readenum =(String) props.get("readenum");       //读取配置中枚举型转proto文件生成的路径
        readjava =(String) props.get("readjava");       //读取配置中普通型转proto文件生成的路径
        input_back =(String) props.get("input_back");       //读取配置中生成协议号所读取的文件的路径
        out =(String) props.get("out");                     //读取配置中生成proto文件的路径
        input_sql =(String) props.get("input_sql");       //读取配置中生成协议号所读取的文件的路径
        output_sql =(String) props.get("output_sql");       //读取配置中生成协议号所读取的文件的路径
    }


    //写入outagreement配置文件
    public void writeconfig(String filepath,String dd) throws IOException {
        FileWriter out =new FileWriter(filepath);
        out.write(dd);
        out.close();
    }
    //获取读到的要写到配置文件中的内容
    public ArrayList getwrite(String path) throws IOException {

        File file =new File(path);
        if (file.exists()){                    //遍历文件目录赛选文件进行反向取参
            File[] files =  file.listFiles();
            for(File file1:files){
                    String x =  file1.getName().substring(file1.getName().indexOf("."));
                    //后缀名为java才可返回协议号
                    if( x.equals(".java") ) {
                        Filed txt = new Filed();
                        //8为倒着读文件的行数
                        String[] a = txt.readfile(file1.toString(), 8).toString().split("\"");
                        String aa = a[1];
                        String b = txt.readfile(file1.toString(), 8).toString();
                        //协议号分别为4位时才能执行
                        String bb = b.substring(b.indexOf("jor =") + 6, b.indexOf("jor =") + 10);
                        String cc = b.substring(b.indexOf("nor =") + 6, b.indexOf("nor =") + 10);
                        StringBuilder sb = new StringBuilder();
                        sb.append(aa).append("=").append(bb).append(",").append(cc);
                        arrayList.add(sb.toString()+"\r\n");
                    }
            }
        }
        return arrayList;
    }
    private void setInput(String input){
        this.input =input;
    }
    public String getInput(){
        return input;
    }
    private void setCMD(String CMD){
        this.CMD =CMD;
    }
    public String getCMD(){
        return CMD;
    }
    private void setSet_out(String set_out){
        this.set_out =set_out;
    }
    public String getSet_out(){
        return set_out;
    }
    private void setjavaVm(String javavm){
        this.javavm =javavm;
    }
    public String getjavaVm(){
        return javavm;
    }
    private void setcsVm(String csvm){
        this.csvm =csvm;
    }
    public String getcsVm(){
        return csvm;
    }
    private void setOutput(String output){ this.output =output; }
    public String getOutput(){
        return output;
    }
    private void setjsonVm(String jsonvm){
        this.jsonvm =jsonvm;
    }
    public String getjsonVm(){
        return jsonvm;
    }
    public String getEnumvm() {
        return enumvm;
    }

    public void setEnumvm(String enumvm) {
        this.enumvm = enumvm;
    }

    public String getProtovm() {
        return protovm;
    }

    public void setProtovm(String protovm) {
        this.protovm = protovm;
    }
    public String getReadenum() {
        return readenum;
    }

    public void setReadenum(String readenum) {
        this.readenum = readenum;
    }

    public String getReadjava() {
        return readjava;
    }

    public void setReadjava(String readjava) {
        this.readjava = readjava;
    }
    public String getInput_back() {
        return input_back;
    }

    public void setInput_back(String input_back) {
        this.input_back = input_back;
    }
    public String getOut() {
        return out;
    }

    public void setOut(String out) {
        this.out = out;
    }

    public String getSqlvm() {
        return sqlvm;
    }

    public void setSqlvm(String sqlvm) {
        this.sqlvm = sqlvm;
    }
    public String getInput_sql() {
        return input_sql;
    }

    public void setInput_sql(String input_sql) {
        this.input_sql = input_sql;
    }

    public String getOutput_sql() {
        return output_sql;
    }

    public void setOutput_sql(String output_sql) {
        this.output_sql = output_sql;
    }
}

